﻿using System;
using System.Collections;
using System.Collections.Generic;
//using IBatisNet.DataAccess;
using Wsitech.Model;
using Wsitech.Utility;
using System.Web;


namespace Wsitech.BLL
{
    /// <summary>
    /// 功能：     LogInfo业务逻辑实现
    /// 作者：     LI
    /// 日期：     2012/6/21
    /// </summary>
    public class LogInfoBLL : BaseBLL
    {
        private Wsitech.Persistence.Interface.ILogInfoDao dao = null;

        private LogInfoBLL()
        {
            dao = Wsitech.Persistence.Dao.LogInfoSqlMapDao.Instance;
        }

        #region （懒汉）单例模式
        private static LogInfoBLL instance = null;
        private static object syncRoot = new object();
        public static LogInfoBLL Instance
        {
            get
            {
                if (instance == null)
                {
                    lock (syncRoot)
                    {
                        if (instance == null)
                        {
                            instance = new LogInfoBLL();
                        }
                    }
                }
                return instance;
            }
        }
        #endregion


        #region	基本功能 不能修改


        /// <summary>
        /// 根据主键得到明细
        /// </summary>
        /// <returns></returns>
        public LogInfo GetDetail(System.String logid)
        {
            try
            {
                return dao.GetDetail(logid);
            }
            catch
            {
                throw;
            }
        }


        /// <summary>
        /// 得到列表
        /// </summary>
        /// <returns></returns>
        public IList<LogInfo> GetList()
        {
            try
            {
                IList<LogInfo> list = dao.GetList();
                return list;
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 通过不同参数得到列表
        /// </summary>
        /// <param name="TopCounts"></param>
        /// <returns></returns>
        private IList<LogInfo> GetListByParams(object TopCounts, LogInfo loginfo)
        {
            try
            {
                Hashtable ht = new Hashtable();
                ht.Add("TopCounts", TopCounts);
                IList<LogInfo> list = dao.GetListByParams(ht);
                return list;
            }
            catch
            {
                throw;
            }
        }



        /// <summary>
        /// 新建
        /// </summary>
        /// <param name="loginfo"></param>
        /// <returns></returns>
        public object Add(LogInfo loginfo)
        {
            try
            {
                return dao.Add(loginfo);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="loginfo"></param>
        /// <returns></returns>
        public int Update(LogInfo loginfo)
        {
            try
            {
                return dao.Update(loginfo);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="LogId"></param>
        /// <returns></returns>
        public int Delete(System.String logid)
        {
            try
            {
                return dao.Delete(logid);
            }
            catch
            {
                throw;
            }
        }

        #endregion


        #region 扩展功能

        #region 添加日志

        /// <summary>
        /// 添加日志
        /// </summary>
        /// <param name="operate"></param>
        /// <param name="data"></param>
        public void AddLog(UtilityEnum.Operation operate, object data)
        {
            if (HttpContext.Current.Session["BackendUser"] != null)
            {
                LogInfo log = new LogInfo();
                log.LogId = Guid.NewGuid().ToString();
                log.Operate = operate.ToString();
                log.UserName = "";
                log.UserName = ((AdminUser)HttpContext.Current.Session["BackendUser"]).UserName;
                log.IpAddress = base.GetClientIP();
                log.CreateTime = DateTime.Now;
                log.JsonData = Newtonsoft.Json.JsonConvert.SerializeObject(data);

                Add(log);
            }
        }

        #endregion

        #region 获取分页列表

        /// <summary>
        /// 获取分页列表
        /// </summary>
        /// <returns></returns>
        public IList<LogInfo> GetPagedList(Hashtable searchParams, int pageindex, int pagesize, ref int count)
        {
            return dao.GetPagedList(searchParams, pageindex, pagesize, ref count);
        }

        #endregion

        #endregion


    }
}
